package com.rtuwrapper.messaging;

import com.rtuwrapper.processing.Precision;

import static com.rtuwrapper.ModbusConstants.READ_FLOAT;
import static com.rtuwrapper.ModbusConstants.READ_REGISTER;

/**
 * Created by westl on 2018/9/10 0010.
 */

public class ReadFloatRequest extends BaseRequest<Precision, Float> {

    public ReadFloatRequest() {
        super(READ_FLOAT);
    }

    public ReadFloatRequest(int address) {
        super(READ_FLOAT, new Precision(address, 0));
    }

    @Override
    public void setData(int address, Float value) {
        setModbusDataObject(new Precision(address, value));
    }

    @Override
    public void setValue(Float value) {
        setModbusDataObject(new Precision(-1, value));
    }

    @Override
    public byte[] getEncodedMessage(int slaveId) {
        return getMessageProcessor().buildReadMessage(slaveId, READ_REGISTER, getModbusData().getAddress(), 2);
    }
}